package ReadWriteLock;

import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

public class demo1 {
    public static void main(String[] args) {
        MyReentrantLock myReentrantLock = new MyReentrantLock();
        //读取数据
        for (int i = 0; i < 100; i++) {
            new Thread(()->{
                System.out.println(Thread.currentThread().getName() + "-->读取数据为: " + myReentrantLock.readData());
            }).start();

        }

        //写数据
        for (int i = 0; i < 100; i++) {
            new Thread(()->{
               myReentrantLock.writeData(1);
            }).start();
        }

        for (int i = 0; i < 100; i++) {
            new Thread(()->{
                System.out.println(Thread.currentThread().getName() + "-->读取数据为: " + myReentrantLock.readData());
            }).start();

        }
    }
}
